home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Utilities / Text and Speech / BBEdit 2.2.2 / BBEdit Extensions / Sources / EducateQuotes.c < prev    next >
C/C++ Source or Header  |  1992-09-27  |  1KB  |  90 lines

  1. #include <SetupA4.h>
  2.  
  3. #include "ExternalInterface.h"
  4.  
  5. static Boolean quote_breaks[256];
  6.  
  7. static void init_quote_breaks(void)
  8. {
  9.     short i;
  10.     
  11.     for (i = 0; i < 256; i++)
  12.         quote_breaks[i] = FALSE;
  13.         
  14.     quote_breaks['\t'] = TRUE;
  15.     quote_breaks['\r'] = TRUE;
  16.     quote_breaks[0x00CA] = TRUE;
  17.     quote_breaks[' '] = TRUE;
  18.     quote_breaks['('] = TRUE;
  19.     quote_breaks['{'] = TRUE;
  20.     quote_breaks['['] = TRUE;
  21.     quote_breaks[0x00D2] = TRUE;
  22.     quote_breaks[0x00D4] = TRUE;
  23. }
  24.  
  25. pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w)
  26. {
  27.     Handle h;
  28.     
  29.     long i, len;
  30.     
  31.     Boolean changed = FALSE;
  32.     register unsigned char c;
  33.     register unsigned char *p;
  34.     
  35.     RememberA0();
  36.     SetUpA4();
  37.     
  38.     changed = FALSE;
  39.     h = callbacks->GetWindowContents(w);
  40.     
  41.     asm
  42.     {
  43.         movea.l    h, a0
  44.         _GetHandleSize
  45.         move.l    d0, len
  46.     }
  47.         
  48.     init_quote_breaks();
  49.     
  50.     callbacks->StartProgress("\pConverting Quotes…", len, FALSE);
  51.     
  52.     p = (unsigned char *)*h;
  53.     for (i = 0; i < len; i++)
  54.     {
  55.         callbacks->DoProgress(i);
  56.         
  57.         c = *p;
  58.         
  59.         if ((i == 0) || quote_breaks[p[-1]])
  60.         {
  61.             if (c == '"')
  62.                 c = '“';
  63.             else if (c == '\'')
  64.                 c = '‘';
  65.         }
  66.         else
  67.         {
  68.             if (c == '"')
  69.                 c = '”';
  70.             else if (c == '\'')
  71.                 c = '’';
  72.         }
  73.         
  74.         if (c != *p)
  75.         {
  76.             *p = c;
  77.             changed = TRUE;
  78.         }
  79.         
  80.         p++;
  81.     }
  82.     
  83.     callbacks->DoneProgress();
  84.     
  85.     if (changed)
  86.         callbacks->ContentsChanged(w);
  87.         
  88.     RestoreA4();
  89. }
  90.